import { FormContext } from '../types'
import { escapeForHtml } from '../utils/htmlUtils'

export class ContextDisplayRenderer {
  render(context?: FormContext): string {
    if (!context || (!context.filePath && !context.lineRange && !context.codeSnippet)) {
      return ''
    }

    return `
      <div class="context-info">
          ${this.renderFileInfo(context.filePath)}
          ${this.renderLineRange(context.lineRange)}
          ${this.renderCodeSnippet(context.codeSnippet)}
      </div>
    `
  }

  private renderFileInfo(filePath?: string): string {
    if (!filePath) return ''
    return `
      <div class="context-item">
          <span class="context-label">文件:</span>
          <span>${escapeForHtml(filePath)}</span>
      </div>
    `
  }

  private renderLineRange(lineRange?: string): string {
    if (!lineRange) return ''
    return `
      <div class="context-item">
          <span class="context-label">行数:</span>
          <span>${escapeForHtml(lineRange)}</span>
      </div>
    `
  }

  private renderCodeSnippet(codeSnippet?: string): string {
    if (!codeSnippet) return ''
    return `
      <div class="context-item">
          <span class="context-label">代码:</span>
          <div class="code-snippet">${escapeForHtml(codeSnippet)}</div>
      </div>
    `
  }
}
